package com.example.kafkademo.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class EventProducer {
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    public void sendEvent() {
        String message = "kzf test";
        kafkaTemplate.send("topic-demo", message);
    }
    public void sendEvent2() {
        Message<String> message = MessageBuilder.withPayload("kzf test Message")
                .setHeader(KafkaHeaders.TOPIC,"topic-demo")
                .build();
        kafkaTemplate.send(message);
    }
}
